@extends('admin.common.main')

@section('cnt')
@endsection
<body>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4">
        <ol class="breadcrumb">
            <li>
                <a href="index.html">主页</a>
            </li>
            <li>
                <strong>文章管理</strong>
            </li>
        </ol>
    </div>
</div>
{{-- 消息提示 --}}
@include('admin.common.msg')
<form action="{{route('admin.article.update',$article)}}" method="post" enctype="multipart/form-data"  class="form-horizontal">
    @csrf
    @method('PUT')
    <div class="form-group">
        <label class="col-sm-2 control-label">文章标题：</label>
        <div class="col-sm-10">
            <input type="text" name="title" class="form-control" value="{{$article['title']}}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">文章描述：</label>
        <div class="col-sm-10">
            <input type="text" name="desc" class="form-control" value="{{$article['desc']}}"> <span class="help-block m-b-none"></span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">文章封面：</label>
        <div class="col-sm-10">
            <input type="hidden" name="picPre" value="{{$article['pic']}}">
            <input type="file" name="pic" id="imgMark" class="form-control" value=""><br/>
            <img id="imgPre" src="{{$article['pic']}}"  height="100px" class="img-rounded" />
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">文章内容：</label>
        <div class="col-sm-10">
            <textarea id="text" name="body" cols="30" rows="10" value="{{$article['body']}}"></textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label"></label>
        <div class="col-sm-10">
            <input class="btn btn-primary radius" type="submit" value="提交">
        </div>
    </div>
    <div class="hr-line-dashed"></div>
</form>
@section('js')
    <!-- 加载编辑器的容器 -->
    <script id="container" name="content" type="text/plain"></script>
    <!-- 配置文件 -->
    <script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="/ueditor/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->

    <script type="text/javascript">
        var ue = UE.getEditor('text',{
            initialFrameHeight:200,
        });

        ue.ready(function() {//编辑器初始化完成再赋值
            let content = {
              info : {!! $article !!}
            }
            ue.setContent(content.info.body);  //赋值给UEditor
        });
        {{--("{{$item['body']}}")--}}
            function preImg(sourceId, targetId) {
            if (navigator.userAgent.indexOf("MSIE")>=1) {
                url = document.getElementById(sourceId).value;
            } else if(navigator.userAgent.indexOf("Firefox")>0) {
                url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));
            } else if(navigator.userAgent.indexOf("Chrome")>0) {
                url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));
            }
            document.getElementById(targetId).src = url;
        }

        $("#imgMark").on('change', function(){
            preImg('imgMark','imgPre');
        })
    </script>
</body>
@endsection
